var myname = "madison"
var getName = function(){
    return "madison"
}

console.log(`hello ${myname}`)
console.log(`hello ${getName()}`)

console.log(`<div>
<span>${myname}</span>
<span>${getName()}</span>
<div>xxxx</div>
</div>
`)



function test(templete,name,age){
    console.log(templete)
    console.log(name)
    console.log(age)
}

var getAge = function(){
    return 18;
}

test`hello my name is ${myname}, i'm ${getAge()}`


var myname: string = 'zs'
myname = 23

//类型推断
var alias = 'xixi'
alias = 12;

var yourname: any = "sd"
yourname = 3

var age: number = 2

var man: boolean = false

function test1(name: string): string{
    return '';
}
test1('23')

class Person{
    name:string;
    age:number;
}

var zhuangsen: Person = new Person()
zhuangsen.name = 'zs'
zhuangsen.age = 18

var myname: string = 'sd'
function test3(a:string,b?:string,c:string='cc'){
    console.log(a);
    console.log(b);
    console.log(c);
}

test3('a','b')
test3('aa')
var args = ['a1','b2','c3']
test3(...args)

function fun1(...args: number[]){
    args.forEach(function(arg){
        console.log(arg);
    })
}

fun1(1,2,3)
fun1(1,2,3,4,5)



function getStock(){
    return{
        code: 'IBM',
        price: 100
    }
}

function getStock1(){
    return{
        code: 'IBM',
        price: {
            price1:100,
            price2:200
        },
        aaa:'xixi',
        bbb:'haha'
    }
}

var stock = getStock();
var code = stock.code;
var price = stock.price;
//析构表达式
var{code ,price} = getStock();
var{code:codex,price} = getStock();

var {code ,price:{price1,price2}} = getStock1()

var array1:number[] = [1,2,3,4,'2'];

var [number1,,,number2] = array1;
var [number1,number2,...others] = array1;

function doSomething([number1,number2,...others]:number[]){
    console.log(number1);
    console.log(number2);
    console.log(others);
}

doSomething(array1);

var sum = (arg1,arg2) => arg1 + arg2;

var sum = arg1 =>{
    console.log(arg1)
}

var myArray = [1,2,3,4]

console.log(myArray.filter(value=>value%2));

function getStock2(name:string){
    this.name = name;
    setInterval(function(){
        console.log('name is :'+this.name)
    },1000);
}
var stock = new getStock2("IBM");

function getStock2(name:string){
    this.name = name;
    setInterval(()=>{
        console.log('name is :'+this.name)
    },1000);
}

var myArray = [1,2,3,4]
myArray.desc = 'four number';

myArray.forEach(value => console.log(value))

for(var n in myArray){
    console.log(n);
    console.log(myArray[n]);
}

for(var n of myArray){
    console.log(n)
}
